$(function () {
	getUserTag();
})
function getUserTag(){
	$("#userCard .user_card").each(function () {
		var panel1 = $(this).find(".panel1");
		var right = $(this).find(".right");
		var userCardId = $(this).find("input[id='userCardId']").val();
		var userTag = $.ajax({
			url : "getUserTag",
			type : "GET",
			data :{userId:userCardId}
		})
        var s ="";
		userTag.done(function (result) {
			var tagList = result.extend.tagList;
			if (tagList.length == 3){
                $.each(tagList,function () {
                    s = "<li><div class='tag'><span class='tag_name'>"+ this.tagName +"</span><span class='tag_count'>*</span></div></li>";
                    getRecommendArticle(this.tagId,right);
                    $(panel1).find("ul").append(s);
                });
			} else if (tagList.length == 2) {
                getRecommendArticle(1,right);
                $.each(tagList,function () {
                    s = "<li><div class='tag'><span class='tag_name'>"+ this.tagName +"</span><span class='tag_count'>*</span></div></li>";
                    getRecommendArticle(this.tagId,right);
                    $(panel1).find("ul").append(s);
                });
			} else if (tagList.length == 1) {
                getRecommendArticle(1, right);
                getRecommendArticle(1, right);
                $.each(tagList, function () {
                    s = "<li><div class='tag'><span class='tag_name'>" + this.tagName + "</span><span class='tag_count'>*</span></div></li>";
                    getRecommendArticle(this.tagId, right);
                    $(panel1).find("ul").append(s);
                });
            } else {
				getRecommendArticle(1,right);
				getRecommendArticle(1,right);
				getRecommendArticle(1,right);
			}
        });


    })
}

function getRecommendArticle(tagId,obj) {
	var getRA = $.ajax({
		url : "getRecommendArticle",
		type : "GET",
		data : {tagId : tagId}
	});
	getRA.done(function (result) {
		if (result.code == 100){
            var article = result.extend.article;
            var a = "<a href='article/"+ article.articleId+"' style='margin-top:10px;text-decoration:none;display:block;'>" + article.simContent + "</a>"
            $(obj).find(".user-name").append(a);
		}
    })
}

$(window).load(function() {
	$('.tag').each(function(i) {
		setTimeout(function() {
		    $('.tag:eq('+i+')').css({ display: 'block', opacity: 0 }).stop().animate({ opacity: 1 }, 'easeInOutExpo'); 
		    	}, 250 * (i + 1));
		    });
			$('.tag').hover(function() {
				$(this).stop().animate({ paddingRight: ($('.tag_count', this).outerWidth() - 5) }, 'easeInOutExpo');
			}, function() {
		$(this).stop().animate({ paddingRight: 5 }, 'easeInOutExpo');
	});
});